import { getMessage } from '@inbiz/react';
import type { IConfigItemEngineProps } from '../web/index';
import type { GeneralField } from '@formily/core';

export const formatPorps = (props: IConfigItemEngineProps, field: GeneralField) => {
  const indexIibraryConfig = props.indexIibraryConfig?.map((configs) => {
    const item = { ...configs };
    item.configs = item.configs?.map((data) => {
      const config = { ...data };
      config.title = getMessage(config.title);
      config.sortField = config.sortField?.map((sortItem) => {
        return {
          ...sortItem,
          IndexFieldDesc: getMessage(sortItem.IndexFieldDesc),
        };
      });
      config.columnField = config.columnField?.map((columnItem) => {
        return {
          ...columnItem,
          IndexFieldDesc: getMessage(columnItem.IndexFieldDesc),
        };
      });
      return config;
    });
    return item;
  });
  return { ...props, indexIibraryConfig, boxHeight: field.decoratorProps?.style?.height };
};
